-module(mutex).
-export([wait/0, signal/0, start/0]).
-export([init/1]).

start() ->
    register(mutex, spawn(?MODULE, init, [free])).

init(State) ->
    receive
	{wait, From} ->
	    From ! State,
	    init(busy);
	singal ->
	    init(free);
	sotp ->
	    ok
    end.

wait() ->
    mutex ! {wait, self()},
    receive
	busy ->
	    wait();
	free ->
	    ok
    end.

signal() ->
    mutex ! signal.

    
